# -*- coding: utf-8 -*-
"""
@Project: base_python
@File: remember_me.py
@Author: PC
@Date: 2025/2/8
@Description: 
"""
import json
def get_store_username():
    filename= 'username.json'
    try:
        with open(filename) as f_obj:
            username = json.load(f_obj)
    except FileNotFoundError:
        return  None
    else:
        return username

def  get_new_username():
    username = input("What is your name?")
    filename = 'username.json'
    with open(filename, 'w') as f_obj:
        json.dump(username, f_obj)
    return username
def greet_user():
    """问候用户，并指出其名字"""
    username = get_store_username()


    if username:
        print(f"Is your name {username}? (yes/no)")
        confirm=input().lower()
        if confirm=="yes":
            print("Welcome back," + username + "!")
        else:
            username = get_new_username()
            print("We'll remember you when you come back," + username + "!")

    else:
        username = get_new_username()
        print("We'll remember you when you come back," + username + "!")


greet_user()